
var helpOut_html = "helpOut/helpOut-welcome.html";



var help_themes = new Ext.data.SimpleStore({
    fields: ['theme', 'css'],
    data: [['默    认', 'ext-all.css'], ['咖啡色', 'xtheme-human.css'], ['银红色', 'xtheme-silverCherry.css'], ['浅灰色', 'xtheme-tp.css'], ['亮黑色', 'xtheme-slickness.css'], ['纯黑色', 'xtheme-dcs.css'], ['蓝灰色', 'xtheme-slate.css']]
});
var help_color_change = new Ext.form.ComboBox({
    triggerAction: "all",
    fieldLabel: '切换系统皮肤',
    forceSelection: true,
    typeAhead: true,
    emptyText: "切换系统皮肤",
    width: 195,
    store: help_themes,
    displayField: "theme",
    valueField: "css",
    mode: "local",
    editable: false,
    listeners: {
        'select': function(e){
            var conboBoxValue = help_color_change.getValue();
            new Ext.state.CookieProvider().set('color', conboBoxValue);
            Ext.util.CSS.swapStyleSheet('theme', 'css/' + conboBoxValue);
        }
    }
});


setTimeout(function(){
    Ext.get('help-loading').remove();
    Ext.getDom('help-header').style.visibility = 'visible';
    var vp = new Ext.Viewport({
        layout: 'border',
        defaults: {
            collapsible: true,
            split: true
        },
        items: [{
            xtype: 'textfield',
            region: 'north',
            applyTo: 'help-header',
            height: 60,
            split: false
        }, {
            region: 'south',
            contentEl: 'south',
            split: false,
            height: 28,
            minSize: 28,
            maxSize: 28,
            collapsible: false,
            margins: '0 0 0 0'
        }, {
            id: 'accordion-panel',
            layout: 'border',
            region: 'west',
            margins: '2 0 5 5',
            width: 210,
            minSize: 200,
            maxSize: 250,
            bbar: [help_color_change],
            items: [{
                layout: 'accordion',
                region: 'center',
                items: [{
                    title: '导航菜单',
                    border: false,
                    items: [{
                        xtype: 'treepanel',
                        border: false,
                        rootVisible: false,
                        autoScroll: true,
                        loader: new Ext.tree.TreeLoader({
                            dataUrl: 'js/inHelp/tree-data-out.json'
                        }),
                        root: new Ext.tree.AsyncTreeNode(),
                        listeners: {
                            'click': function(module){// module为叶子节点
                                try {// 目的：动态加载外部js
                                    var sn = this.selModel.selNode || {};
                                    
                                    // pid为父模块的名字
                                    var pid = module.id.substring(0, module.id.indexOf('-'));
                                    var contentPanel = Ext.getCmp('content-panel');
                                    // 缓存模块实现：首先判断该是否已经加载过，如果加载了，则设置为激活状态。
                                    if (contentPanel.uxmodules != undefined &&
                                    contentPanel.uxmodules[module.id]) {
                                        contentPanel.layout.setActiveItem(module.id);
                                        return;
                                    }
                                    helpOut_html = pid + '/' + module.id + '.html';
                                    contentPanel.load({
                                        url: helpOut_html,
                                        scripts: true,
                                        timeout: 30
                                    });
                                    
                                } 
                                catch (e) {
                                }
                            }
                        }
                    }]
                }]
            }]
        }, {
            id: 'content-panel',
            region: 'center',
            layout: 'card',
            autoScroll: true,
            margins: '2 5 5 0',
            collapsible: false,
            activeItem: 0,
            border: false
        }]
    });
    Ext.getCmp('content-panel').load({
        url: helpOut_html,
        scripts: true,
        timeout: 30
    });
    var css = new Ext.state.CookieProvider().get('color');
    Ext.util.CSS.swapStyleSheet('theme', 'css/' + css);
}, 250);
